package com.github.lzyzsd.jsbridge.example;

import android.util.Log;

import com.blankj.utilcode.util.ToastUtils;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;
import com.google.gson.JsonObject;

/**
 * <pre>
 * Description: 提交信息到web端
 * Copyright  : Copyright (c) 2022
 * Email      : jusenr@163.com
 * Author     : Jusenr
 * Date       : 2022/1/27 9:51
 * Project    ：JsBridge-1.0.4
 * PackageName：com.github.lzyzsd.jsbridge.example.
 * </pre>
 */
public class FunctionInJs extends BaseBindHandler {

    private static final FunctionInJs info = new FunctionInJs();

    private FunctionInJs() {
    }

    public static FunctionInJs getInstance() {
        return info;
    }

    @Override
    public void bindHandler(BridgeWebView webView) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("name", "JsBridgeTest");
        jsonObject.addProperty("author", "Jusenr");
        jsonObject.addProperty("time", "2022/1/27 9:51");

        webView.callHandler("functionInJs", jsonObject.toString(), new CallBackFunction() {
            @Override
            public void onCallBack(String data) {
                Log.i(TAG, "callHandler handler = functionInJs, data from web = " + data);
                ToastUtils.showShort("JS返回: %s", data);
            }
        });
    }
}
